﻿using System;

namespace Rules
{
    public class GreaterThanOrEqualToRule<T> : RuleBase<T> where T : IComparable
    {
        public GreaterThanOrEqualToRule(T minimum, string propertyName)
            : base(propertyName)
        {
            Minimum = minimum;
        }

        public GreaterThanOrEqualToRule(T minimum, string propertyName, string description)
            : base(propertyName, description)
        {
            Minimum = minimum;
        }

        public T Minimum { get; private set; }

        protected override bool DoEvaluate(T subject)
        {
            return subject.CompareTo(Minimum) >= 0;
        }

        protected override string GetDefaultDescription()
        {
            return string.Format("{0} must be at least {1}", PropertyName, Minimum);
        }
    }
}